Option Strict Off
Option Explicit On 

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class DataGridCustom
    Inherits DataGrid

    Private Const OFFSET As Integer = 5
    'Fields
    'Constructors
    'Events
    'Methods
    Public Sub New()
        'Warning: Implementation not found
    End Sub

    Protected Overloads Overrides Sub OnCurrentCellChanged(ByVal e As EventArgs)
        MyBase.OnCurrentCellChanged(e)

        If (Control.MouseButtons <> MouseButtons.Left) Then
            Dim rect As Rectangle
            rect = Me.GetCellBounds(Me.CurrentCell)
            Dim e1 As MouseEventArgs
            e1 = New MouseEventArgs(MouseButtons.Left, 0, OFFSET, (rect.Y + OFFSET), 0)
            OnMouseDown(e1)
        End If
    End Sub

    Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
        Dim hti As DataGrid.HitTestInfo

        hti = Me.HitTest(e.X, e.Y)

        If (hti.Type = HitTestType.Cell) Then
            Dim e1 As MouseEventArgs
            e1 = New MouseEventArgs(e.Button, e.Clicks, OFFSET, e.Y, e.Delta)
            MyBase.OnMouseDown(e1)
        Else
            MyBase.OnMouseDown(e)
        End If
    End Sub
End Class
